1. /* slominus.cpp by K.Tsuru */
  2. // function ID = 225 DRADIX, BRADIX
  3. /****************
  4. SLong class
  5. operator-() m-n
  6. ******************/
  7. #ifndef SN_H
  8. #include "sn.h"
  9. #endif
  10. SLong operator-(const SLong& m, const SLong& n){
  11. // check radix in LLSub and LLAdd
  12. // if(m.Radix() != n.Radix()) m.SetError(m.RADIX_ERR, "SL \'-\'", 202);
  13. //This function is also used in Knuth's divide of SInteger class.
  14. // if((m.Radix() != DRADIX)||(n.Radix() != DRADIX)) m.SetError(m.RADIX_ERR, "SL -", 202);
  15. int c, s = m.Sign(202) * n.Sign(202);
  16. SLong r(m.Type(), 0);
  17. if( !s ){ //One of m and n is zero.
  18. if( m.Sign() == 0 ){
  19. r = n; r.ChangeSign(202); // r = -n;
  20. return r;
  21. } else return m;
  22. } else if( s < 0 ){//diffrent sign
  23. r = n; r.ChangeSign(202); // r = -n;
  24. return LLAdd(m, r); //The sign is same as that of m and set by LLAdd().
  25. } else { //same sign
  26. c = LLCompare(m, n);
  27. if(c > 0) return LLSub(m, n); // m > n
  28. if(c < 0){ //m<n, m-n = -(n-m)
  29. r = LLSub(n, m); //r=n-m
  30. r.ChangeSign(202); // r = -r;
  31. return r;
  32. }
  33. r.SetZero();
  34. return r; // c = 0 : m = n
  35. }
  36. }

slominus.cpp : last modifiled at 2016/05/01 10:16:55(1,131 bytes)
created at 2017/10/07 10:26:50
The creation time of this html file is 2017/11/09 14:52:03 (Thu Nov 09 14:52:03 2017).